"""
函数 Function
"""
from docutils.nodes import address

# def name():
#     # 函数体
#     pass
#
# print("Hello World")
#
# print(len("666"))


# def calculators(start, end):
#     result = 0
#     for i in range(start, end + 1):
#         result += i
#     # return result
#     print(result)
#
# # total_num = calculators(101, 506)
# # print(total_num)
#
# calculators(101, 506)


# def abs(x):
#     result = len(x)
#     return result
#
# num = abs("666")
# print(num)

"""
函数的命名规则
"""
# # 一般使用蛇形命名法
# def my_name():
#     pass
#
# # 我的个人习惯，使用小驼峰命名法
# def myName():
#     pass

# def 胡歌():
#     name = "Shawn Holmes Hu"
#     age = 18
#     address = "Beijing"
#     print(name, age, address)
#
# 胡歌()

"""
形参与实参
Parameter AND Argument
"""
# def add(x, y):
#     result = x + y
#     return result


# num = add(89512, 1248115)
# print(num)

# temp = add
# print(temp(154, 555))

# def calculate_num(i, j):
#     """
#     用于统计两个数值之间的整数和
#     :param i: 起始值（包含此值）
#     :param j: 终止值（包含此值）
#     :return: 起始值到终止值之间的所有整数和
#     """
#     result = 0
#     for n in range(i, j + 1):
#         result += n
#     return result

"""
参数的类型
"""
# # 位置参数
# def sayHello(name, age, address):
#     print(f"Hello {name}, you are {age} years old, and you live in {address}")
#
# # sayHello("Shawn", 18, "Beijing")
#
# # 命名参数
# sayHello(age = 18, address="Beijing", name="Shawn")

# 可变参数（可变数量的参数）
# def add(*args): # *args 表示接受任意数量的参数，参数类型为元组
#     result = 0
#     for n in args:
#         result += n
#     return result
#
# print(add(588, 194, 666, 123))

# def temp(*a, b, c, d):
#     print(a, b, c, d)
#
# temp(1, 2, 3, 4, 5, 6, 7, b = 8, c = 9, d = 10)

#
# def temp(a, b, *c, **d): # **d 表示接受任意数量的关键字参数，参数类型为字典
#     print(a, b, c, d)
#
# temp(1, 2, 3, 4, 5, name = "Shawn", age = 18, address = "Beijing")
#

"""
lambda 表达式（匿名函数）
"""
# f = lambda x, y: x + y
# print(f(1, 3))

"""
递归函数
"""
# def calculators(end):
#     result = 0
#     for i in range(1, end + 1):
#         result += i
#     print(result)
#
# calculators(100)
# calculators(50)

# def temp(end):
#     if end == 1:
#         return 1
#     else:
#         return end + temp(end - 1)
#
# print(temp(100))

"""
全局变量与局部变量
"""

# a = 10
#
# def temp():
#     global a
#     # a = 20
#     a += 1
#     print(a)
#
# temp()
# # print(a)
b = 1
a = 100
def outer():
    b = 10

    def inner():
        nonlocal b
        print("inner b:", b)

        # b = 20
        global a
        a = 1000
    inner()
    print("outer b:", b)
outer()
print("a:", a)
